#include "umode.h"

static UMode::Candidates cans;

int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        printf("Usage: %s  u S1 us C us S2\n", argv[0]);
        return -1;
    }
    UMode um;
    um.Init();
    for(int i = 1; i < argc; i++)
    {
        printf("Input:%s\n", argv[i]);
        if(argv[i][0] == 'C')
        {
            printf("Will call Clear\n");
            um.Clear();
            continue;
        }
        if('S' == *argv[i])
        {
            auto idx = std::atoi(argv[i]+1);
            if(idx > 0 && idx <= cans.size())
            {
                auto commit = um.Select(idx-1);
                printf("Select:%d\nCommit:%s\n", idx, commit.c_str());
            }
            else
            {
                printf("Invalid input:[%s]\n", argv[i]);
            }
            continue;
        }
        if('L'== *argv[i])
        {
            printf("Will loadd dict %s\n", argv[i]+1);
            um.LoadDict(argv[i]+1);
            continue;
        }
        cans = um.Decode(argv[i]);
        puts("Output:");
        printf("\tComposition:%s\n", um.GetComposition().c_str());
        printf("\tCandidates:");
        for(auto & can : cans)
        {
            printf("%s ", can.c_str());
        }
        putchar('\n');
    }
    return 0;
}
